package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/listStudentSevrlet")
public class listStudentSevrlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader br = new BufferedReader(new FileReader("D:\\misao.txt"));
        ArrayList<Student> list = new ArrayList<>();
        String len;
        while ((len = br.readLine())!=null){
            Student stu = new Student();
            String[] arr = len.split(",");
            stu.setName(arr[0]);
            stu.setAge(Integer.parseInt(arr[1]));
            stu.setScoer(Integer.parseInt(arr[2]));
            list.add(stu);

            }
            req.getSession().setAttribute("sutdens",list);

                resp.sendRedirect("/stu/listStudent.jsp");

        }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
